-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DependencyInjection] Improved "optional argument" documentation #6511
Conversation
Not sure if this should be expanded into a code block showing the |
Didn't you mean |
@xabbuh yeah that is what i meant - should this be expanded into a new section with a new set of code examples? or shall i just expand the note? |
I think a new section with a dedicated example (e.g. a collection argument) that shows the difference would be a good idea. |
2c561c2
to
322a5fa
Compare
|
||
- When used as a standard argument, the argument will be set to ``null``; | ||
- When used within a method call, the method call itself will be removed; | ||
- When used on a collection argument, the argument will be removed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only in Symfony 3.0 master
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think we should omit it here and add it after merging your PR up to master
.
- When used within a method call, the method call itself will be removed; | ||
- When used on a collection argument, the argument will be removed. | ||
|
||
Setting missing dependencies to null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting Missing Dependencies to null (not sure if we should use literals for null here)
I think I would move the "ignoring" strategy after the "set null" strategy. This way, you could say that it's basically the same strategy, but with the following differences (and then lists these differences). |
f5329b7
to
0cf3bab
Compare
Updated, reworded, rearanged and changed the "ignore" example to use a method call. |
service does not exist then you may use the ``null`` strategy as follows: | ||
|
||
.. configuration-block:: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code block with yaml is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feature isn't supported with YAML afaict.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really? if yes, sorry, i didn't know that, but then this would be a good information here ;-)
what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its given just below the code examples :)
On Fri, Apr 29, 2016 at 06:09:01AM -0700, Oskar Stark wrote:
In [1]book/service_container.rst:
Sometimes, one of your services may have an optional dependency, meaning
that the dependency is not required for your service to work properly. In
the example above, theapp.mailer
service must exist, otherwise an exception
will be thrown. By modifying theapp.newsletter_manager
service definition,
-you can make this reference optional. The container will then inject it if
-it exists and do nothing if it doesn't:
+you can make this reference optional, there are two strategies for doing this.
+
+Setting Missing Dependencies to null
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you want to explicitly set the argument tonull
in the event that the
+service does not exist then you may use thenull
strategy as follows:
+
+.. configuration-block::
+really? if yes, sorry, i didn't know that, but then this would be a good
information here ;-)what do you think?
—
You are receiving this because you authored the thread.
Reply to this email directly or [2]view it on GitHubReverse link: [3]unknown
References
Visible links
- [DependencyInjection] Improved "optional argument" documentation #6511 (comment)
- https://github.com/symfony/symfony-docs/pull/6511/files/0cf3bab63f400c6d04ff7baa1664c6f2b0f66d73#r61573614
- https://github.com/symfony/symfony-docs/pull/6511/files/0cf3bab63f400c6d04ff7baa1664c6f2b0f66d73#r61573614
This is the first time I understand the difference, thanks for submitting this patch! 👍 |
Expanded the documentation for the "on invalid" behaviors for optional arguments.
Updated |
…ntation (dantleech) This PR was merged into the 2.3 branch. Discussion ---------- [DependencyInjection] Improved "optional argument" documentation | Q | A | ------------- | --- | Doc fix? | yes | New docs? | yes | Applies to | 2.3+/master The `on-ignore=null` behavior of the DI container arguments is currently undocumented. TODO: - Add `- When used on a collection argument, the argument will be removed.` list item in master. Commits ------- 84b1037 Improved "optional argument" documentation"
Thank you @dantleech for adding this missing piece of information. I also opened #6550 so that we do not forget to update the docs for Symfony 3.1 with the changes made for invalid reference collection arguments. |
The
on-ignore=null
behavior of the DI container arguments is currently undocumented.TODO:
- When used on a collection argument, the argument will be removed.
list item in master.